//
//  BaseViewController.m
//  ChartsDemo
//
//  Created by yunda on 2021/7/30.
//

#import "BaseViewController.h"

@interface BaseViewController ()

// 返回按钮
@property (strong, nonatomic)  UIButton *backButton;

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self j_appearance];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
}

- (void)setupNavigationItems{
    [super setupNavigationItems];
    if ([self hookNeedBackBarButtonItem]) {
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:self.backButton];
    }else{
        self.navigationItem.leftBarButtonItem = nil;
        self.navigationItem.hidesBackButton = YES;
    }
}

/// 是否需要返回按钮
- (BOOL)hookNeedBackBarButtonItem{
    return YES;
}

/// 返回按钮事件
- (void)hookBackBarButtonAction:(UIButton *)sender{
    [ARTNavigation closeViewControllerAnimated:YES];
}

- (nullable UIColor *)titleViewTintColor{
    return [UIColor blackColor];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (UIButton *)backButton{
    if (!_backButton) {
        _backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _backButton.frame = J_Frame(-10, 0, 47, 27);
        [_backButton setImage:J_ImageNamed(@"i_return_black") forState:UIControlStateNormal];
        [_backButton addTarget:self action:@selector(hookBackBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backButton;
}

@end
